feat: mark video as watched after a certain duration#5528
feat: mark video as watched after a certain duration#5528goestav wants to merge 16 commits intoiv-org:masterfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a feature to automatically mark videos as watched after the user has watched them for at least 30 seconds (or fully for videos shorter than 30 seconds). The feature is opt-in via a new user preference and uses client-side tracking to determine when to mark videos as watched. It also removes the previous server-side logic that marked videos as watched upon navigation to a video page, and fixes a bug preventing YouTube/Invidious link updates when seeking backwards.
Key changes:
- Added
mark_watched_after_durationpreference with default value offalseto avoid confusion for existing users - Implemented client-side tracking in player.js to monitor watch time and trigger mark-as-watched after thresholds are met
- Removed automatic server-side marking of videos as watched on page load
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/invidious/config.cr | Added mark_watched_after_duration property to default preferences config |
| src/invidious/user/preferences.cr | Added mark_watched_after_duration property to user preferences struct |
| src/invidious/videos/video_preferences.cr | Added processing and handling of mark_watched_after_duration parameter in video preferences |
| src/invidious/routes/preferences.cr | Added route handling to save the mark_watched_after_duration preference from form submission |
| src/invidious/routes/watch.cr | Removed server-side logic that automatically marked videos as watched on page navigation |
| src/invidious/views/user/preferences.ecr | Added checkbox UI for the new preference in the preferences page |
| src/invidious/views/template.ecr | Added hidden span to expose the preference value to client-side JavaScript (only for logged-in users) |
| locales/en-US.json | Added English translation for the preference label |
| assets/js/player.js | Implemented client-side watch time tracking and auto-mark-as-watched logic, also fixed backward seeking bug |
Comments suppressed due to low confidence (1)
assets/js/player.js:210
- Avoid automated semicolon insertion (93% of all statements in the enclosing function have an explicit semicolon).
time_watched += 1
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
I don't think that's a good thing because we still want to support non js users as long as possible. |
|
Apologies, that was supposed to be ignored only if this feature is enabled. - if watched && preferences.watch_history
+ if watched && preferences.watch_history && !preferences.mark_watched_after_duration
Invidious::Database::Users.mark_watched(user.as(User), id)
endIt should probably be mentioned under the checkbox in the preference page that the feature requires JavaScript though. |
We can do that, without the need for a config option. The simplest way would be to add an extra URL query parameter (like Then the front-end JS will call the right endpoint after the video passes the 5s mark. For non-JS users, it has no impact, as if the query parameter is absent, it continues to do as it did in the past. |
004ed27 to
d999c50
Compare
|
I think this PR is ready now, I implemented @SamantazFox's suggestion. |
|
@SamantazFox or @unixfox could either of you review/merge this PR please? |
This pull request marks videos as watched after watching them for a given amount of time if JavaScript is enabled and also indirectly fixes a bug that prevents YouTube/Invidious links from updating when seeking backwards for the video.
Closes #3794